package org.footballmanager.pandafootball.common.util;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
public class BMIUtil {
	private static final String BMI = "BMI指数为:";
	private static final String THIN = ",偏瘦,相关疾病发病危险性:低（但其它疾病危险性增加）";
	private static final String NORMAL = ",正常,相关疾病发病危险性:平均水平";
	private static final String FAT = ",超重偏胖,相关疾病发病危险性:增加";
	private static final String FATTER = ",超重肥胖,相关疾病发病危险性:中度增加";
	private static final String FATEST = ",超重重度肥胖,相关疾病发病危险性:严重增加";
	private static final String BESTFAT = ",超重极重度肥胖,相关疾病发病危险性:非常严重增加";

	private static Map<Integer, List<Double>> map = new HashMap<>();
	private static List<String> strList = new ArrayList<>();

    private BMIUtil(){}

	private static void initList(){
		List<Double> list = new ArrayList<>();
		list.add(18.5D);
		list.add(25.0D);
		list.add(30.0D);
		list.add(35.0D);
		list.add(40.0D);
		map.put(1, list);
		list = new ArrayList<>();
		list.add(18.5D);
		list.add(23.0D);
		list.add(25.0D);
		list.add(30.0D);
		list.add(40.0D);
		map.put(2, list);
		list = new ArrayList<>();
		list.add(18.5D);
		list.add(24.0D);
		list.add(28.0D);
		list.add(30.0D);
		list.add(40.0D);
		map.put(3, list);
		strList.add(THIN);
		strList.add(NORMAL);
		strList.add(FAT);
		strList.add(FATTER);
		strList.add(FATEST);
		strList.add(BESTFAT);
	}

	private static String getYourInfo(String weight, String height, Integer type){
		initList();
		Double w;
		Double h;
		Double result;
		w = Double.valueOf(weight);
		h = Double.valueOf(height);
		result = w / (h * h);
		List<Double> list = map.get(type);
		if(list != null && !list.isEmpty()){
			for(int i = 0; i < list.size(); i++){
				if(result < list.get(i)){
					return BMI + result + strList.get(i);
				}
			}
		}
		return null;
	}
	
	public static void main(String[] args){
		log.info(BMIUtil.getYourInfo("71", "1.75", 1));
		log.info(BMIUtil.getYourInfo("71", "1.75", 2));
		log.info(BMIUtil.getYourInfo("71", "1.75", 3));
	}
}
